package cn.fl.institution.controller;

import cmm.comm.facade.upload.api.IUploadApiService;
import cmm.comm.facade.upload.condition.SysUlFilesRecQueryCondition;
import cmm.comm.facade.upload.constant.SysUlFilesRecConstant;
import cmm.comm.facade.upload.dto.SysUlFilesRecDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.constant.SysOrgConstant;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.institution.condition.PrjInsRfeRecordQC;
import cn.fl.institution.service.IPrjInsRfeRecordService;
import cn.fl.institution.transform.PrjInsRfeRecordVOTransform;
import cn.fl.institution.vo.PrjInsRfeRecordVO;
import cn.fl.insurance.vo.InsPlcBscInfoVO;
import cn.fl.project.dto.PrjPrdDtlDTO;
import cn.fl.project.service.IProjectApiService;
import cn.fl.ref.fribaseinfo.service.IFriBaseInfoService;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import fl.ref.fribaseinfo.condition.FriBaseInfoQueryCondition;
import fl.ref.fribaseinfo.constant.FriBaseInfoConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.commons.result.ResponseData;
import cn.fl.datacheck.constant.DataCheckConstant;
import cn.fl.datacheck.dto.PrjFileCompltInfoDTO;
import cn.fl.enums.CompltStartTypEnum;
import cn.fl.framework.base.constant.WebBaseConstant;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.institution.api.IPrjInsRfeRecordApiService;
import cn.fl.institution.condition.PrjInsRfeRecordQC;
import cn.fl.institution.constant.PrjInsRfeRecordConstant;
import cn.fl.institution.dto.PrjInsRfeRecordDTO;
import cn.fl.institution.service.IPrjInsRfeRecordService;
import cn.fl.institution.vo.PrjInsRfeRecordVO;
import cn.fl.preloan.IInsPlcBscInfoService;
import cn.fl.preloan.condition.InsPlcBscInfoQueryCondition;
import cn.fl.preloan.condition.PrjPrdInvoiceQueryCondition;
import cn.fl.preloan.dto.insurance.GetInsPlcBscInfoListRequest;
import cn.fl.preloan.dto.insurance.InsPlcBscInfoDTO;
import cn.fl.project.condition.PrjPrdDtlQueryCondition;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.constant.PrjPrdBscInfoConstant;
import cn.fl.project.service.IPrjPrdDtlService;
import cn.fl.project.service.IPrjPrdInvoiceService;
import cn.fl.project.vo.PrjPrdDtlVO;
import cn.fl.project.vo.PrjPrdInvoiceVO;
import cn.fl.ref.fribaseinfo.service.IFriBaseInfoService;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysUlFilesRecService;
import cn.fl.system.vo.SysUlFilesRecVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.constant.facade.framework.constant.SystemConstant;
import fl.ref.fribaseinfo.condition.FriBaseInfoQueryCondition;
import fl.ref.fribaseinfo.constant.FriBaseInfoConstant;
import flow.business.facade.flow.api.IFlowBusinessQueryApiService;
import flow.business.facade.flow.condition.SysFlowSHQueryCondition;
import flow.business.facade.flow.dto.SysFlowSHDTO;
import net.sf.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @Description: 资方补件记录表 控制层
 */
@Controller
@RequestMapping("/insitution/prjInsRfeRecord")
public class PrjInsRfeRecordController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(PrjInsRfeRecordController.class);

	/**
	 * PrjInsRfeRecord 服务层BEAN
	 */
	@Autowired
	private IPrjInsRfeRecordService prjInsRfeRecordService;

	/**
	 * 融资机构基础信息表
	 */
	@Autowired
	private IFriBaseInfoService friBaseInfoService;

	/**
	 * 附件服务
	 */
	@Autowired
	private ISysUlFilesRecService sysUlFilesRecService;

	@Autowired
	private IPrjPrdDtlService prjPrdDtlService;

	@Autowired
	private IPrjPrdInvoiceService prjPrdInvoiceService;

	@Autowired
	private IInsPlcBscInfoService insPlcBscInfoService;

	@Autowired
	private IPrjInsRfeRecordApiService prjInsRfeRecordApiService;

    @Autowired
    private IUploadApiService uploadApiService;

	@Autowired
	private IFlowBusinessQueryApiService flowBusinessQueryApiService;

	/**
	 * 发起流程
	 */
	@RequestMapping(value = "/addFlowStartForAddDocuments.do", method = {RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	public Object addFlowStartForAddDocuments(HttpServletRequest request) throws BaseException {
		BaseLogUtils.newLogger("资方补件发起流程入参信息request=" + JSON.toJSONString(this.getRequestParameter(request))).info();
		String id = request.getParameter("id");
		PrjInsRfeRecordQC prjInsRfeRecordQC = new PrjInsRfeRecordQC();
		prjInsRfeRecordQC.setIsDel(0);
		prjInsRfeRecordQC.setId(Long.parseLong(id));
		List<PrjInsRfeRecordVO> prjInsRfeRecordVOS = prjInsRfeRecordService.queryAll(prjInsRfeRecordQC);
		BaseLogUtils.newLogger("资方补件资料校验查询结果id=" + id + ",prjInsRfeRecordVOS=" + JSON.toJSONString(prjInsRfeRecordVOS)).info();
		if (CollectionUtils.isEmpty(prjInsRfeRecordVOS)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "查询补件记录数据为空");
		}
		PrjInsRfeRecordDTO prjInsRfeRecordDTO = new PrjInsRfeRecordDTO();
		BeanUtils.copyProperties(prjInsRfeRecordVOS.get(0), prjInsRfeRecordDTO);
		prjInsRfeRecordDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		DataResultDTO dataResultDTO = prjInsRfeRecordApiService.addFlowStartForAddDocuments(prjInsRfeRecordDTO, CompltStartTypEnum.START_BY_CSTMSGR.code);
		return dataResultDTO;
	}

    /**
     * 上传
     */
    @RequestMapping(value = "/uploadFileInfo.do", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public Object uploadFileInfo(HttpServletRequest request) throws BaseException {
        BaseLogUtils.newLogger("资方补件上传文件入参信息request=" + JSON.toJSONString(this.getRequestParameter(request))).info();
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_FILE_UPLOAD_SUCC);
        String fileParams = request.getParameter("fileParams");
        String cfgCd = request.getParameter("cfgCd");
        String cfgDtlCd = request.getParameter("cfgDtlCd");
        String orgCd = request.getParameter("orgCd");
        String pkId = request.getParameter("pkId");
        String tabNm = request.getParameter("tabNm");
        if (StringUtils.isBlank(pkId)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_FILE_UPLOAD_FAIL);
        } else {
            JSONArray array = JSONArray.fromObject(fileParams);
            if(null != array && !array.isEmpty() && array.isArray()){//处理附件
                List<SysUlFilesRecDTO> addList = new ArrayList<>();//需要新加的附件内容
                SysUlFilesRecDTO sysUlFilesRecDTO = null;//
                String rootPath = PropertiesCacheUtils.getProperty(SysUlFilesRecConstant.SYS_FILE_UPLOAD_ROOT_PATH);
                for (Object object : array) {
                    net.sf.json.JSONObject upObj = net.sf.json.JSONObject.fromObject(object);
                    String flPath = upObj.optString(SysUlFilesRecConstant.REQUEST_PARAM_FILE_PATH, SysUlFilesRecConstant.REQUEST_PARAM_DEFAULT_UNKNOW);
                    String flNm = upObj.optString(SysUlFilesRecConstant.REQUEST_PARAM_FILE_NAME, SysUlFilesRecConstant.REQUEST_PARAM_DEFAULT_UNKNOW);
                    sysUlFilesRecDTO = new SysUlFilesRecDTO();
                    sysUlFilesRecDTO.setCrtTm(new Date());
                    sysUlFilesRecDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                    sysUlFilesRecDTO.setPkId(pkId);
                    sysUlFilesRecDTO.setFileNm(flNm);
                    sysUlFilesRecDTO.setFilePath(flPath);
                    sysUlFilesRecDTO.setIsDel(BaseConstant.IS_YESNO_NO);
                    sysUlFilesRecDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
                    sysUlFilesRecDTO.setTransFlg(BaseConstant.IS_YESNO_NO);
                    sysUlFilesRecDTO.setPInstId(null);
                    sysUlFilesRecDTO.setTInstId(null);
                    sysUlFilesRecDTO.setCfgCd(cfgCd);
                    sysUlFilesRecDTO.setCfgDtlCd(cfgDtlCd);
                    sysUlFilesRecDTO.setFileRem(null);
                    if ("undefined".equals(orgCd) ||"null".equals(orgCd) || StringUtils.isEmpty(orgCd)){
						sysUlFilesRecDTO.setOrgCd(SysOrgConstant.SYS_ORG_ORG_CD_INIT);
					}else {
						sysUlFilesRecDTO.setOrgCd(orgCd);
					}
                    sysUlFilesRecDTO.setTabNm(tabNm);
                    sysUlFilesRecDTO.setAbsLocPath(rootPath+flPath);
                    sysUlFilesRecDTO.setbId("35279a3dba524cf5a1a6c4b316046491");
                    sysUlFilesRecDTO.setpId("LSAENHUINSPLM");
                    sysUlFilesRecDTO.setAudStsCd("0");
                    addList.add(sysUlFilesRecDTO);
                }
                boolean flag = this.uploadApiService.addSysUlFilesRecListWithIsDel(addList, true);
                BaseLogUtils.newLogger("上传补件资料文件结果pkId=" + pkId + ",cfgCd=" + cfgCd + ",cfgDtlCd=" + cfgDtlCd + ",orgCd=" + orgCd + ",flag=" + flag).info();
            }
        }
        return result;
    }

	/**
	 * 到资方补件页面
	 */
	@RequestMapping(value = "/toPrjFillInfoPage.do", method = { RequestMethod.GET, RequestMethod.POST})
	public ModelAndView toPrjFillInfoPage(HttpServletRequest request) {
		ModelAndView view = new ModelAndView("institution/prjInsRfeRecord/prjFillPage");
		BaseLogUtils.newLogger("资方补件页面入参信息request=" + JSON.toJSONString(this.getRequestParameter(request))).info();
		String id = request.getParameter("id");//主键id 对应流程中dataId
		String fileNode = request.getParameter("fileNode");
		String detailFlag = request.getParameter("detailFlag");
		String isFlow = request.getParameter("isFlow");
		view.addObject("id", id);
		SysFlowSHQueryCondition sysFlowSHQC = new SysFlowSHQueryCondition();
		sysFlowSHQC.setSysCd(WebBaseConstant.SYS_SYS_CD);//系统代码
		sysFlowSHQC.setWordsInTheTable(PrjBscInfoConstant.PRJ_FLOW_S_H_PRJ);//表中字
		sysFlowSHQC.setDataId(Long.parseLong(id));//业务主键
		sysFlowSHQC.setpDefKey(PrjInsRfeRecordConstant.FLOW_DEF_KEY_ADDITIONAL_DOCUMENT);
		sysFlowSHQC.setStatus(BaseConstant.IS_YESNO_YES);
		BaseLogUtils.newLogger("资管补件资料页面查询流程入参id=" + id).info();
		List<SysFlowSHDTO> sysFlowSHDTOS = this.flowBusinessQueryApiService.searchFlowSHDTOList(sysFlowSHQC);
		BaseLogUtils.newLogger("资管补件资料页面查询流程结果id=" + id + ",sysFlowSHDTOS=" + JSON.toJSONString(sysFlowSHDTOS)).info();
		if (CollectionUtils.isNotEmpty(sysFlowSHDTOS)) {
			SysFlowSHDTO sysFlowSHDTO = sysFlowSHDTOS.get(0);
			view.addObject("pNo", sysFlowSHDTO.getPNo());
		}
		view.addObject("fileNode", fileNode);//补件节点 1上传或2验证
		view.addObject("detailFlag", detailFlag);//如果为true 则跳转到修改页面
		view.addObject("isFlow", isFlow);//是否发起流程 1是0否
		PrjInsRfeRecordQC prjInsRfeRecordQC = new PrjInsRfeRecordQC();
		prjInsRfeRecordQC.setIsDel(0);
		prjInsRfeRecordQC.setId(Long.parseLong(id));
		List<PrjInsRfeRecordVO> prjInsRfeRecordVOS = prjInsRfeRecordService.queryAll(prjInsRfeRecordQC);
		BaseLogUtils.newLogger("资方补件资料校验查询结果id=" + id + ",prjInsRfeRecordVOS=" + JSON.toJSONString(prjInsRfeRecordVOS)).info();
		if (CollectionUtils.isNotEmpty(prjInsRfeRecordVOS) && prjInsRfeRecordVOS.get(0) != null) {
			PrjInsRfeRecordVO prjInsRfeRecordVO = prjInsRfeRecordVOS.get(0);
			view.addObject("prjInsRfeRecordVO", prjInsRfeRecordVO);
			List list = JSON.parseObject(prjInsRfeRecordVO.getRefDataCode(), List.class);
			BaseLogUtils.newLogger("资方补件资料转换结果id=" + id + ",list=" + JSON.toJSONString(list)).info();
			List<PrjFileCompltInfoDTO> prjFileCompltInfoDTOList = new ArrayList<>();
			for (Object o : list) {
				prjFileCompltInfoDTOList.add(JSON.parseObject(JSON.toJSONString(o), PrjFileCompltInfoDTO.class));
			}
			BaseLogUtils.newLogger("资方补件资料转换实体对象结果id=" + id + ",prjFileCompltInfoDTOList=" + JSON.toJSONString(prjFileCompltInfoDTOList)).info();
			for (PrjFileCompltInfoDTO prjFileCompltInfoDTO : prjFileCompltInfoDTOList) {
				prjFileCompltInfoDTO.setFileName(prjFileCompltInfoDTO.getFileNm());
			}
			BaseLogUtils.newLogger("资方补件资料重命名文件名称结果id=" + id + ",prjFileCompltInfoDTOList=" + JSON.toJSONString(prjFileCompltInfoDTOList)).info();
			if (CollectionUtils.isNotEmpty(prjFileCompltInfoDTOList)) {
				//客户资料(自然人和法人)、项目资料、租赁物资料、发票资料、保单资料
				List<PrjFileCompltInfoDTO> cstFileList = new ArrayList<>();
				List<PrjFileCompltInfoDTO> prjFileList = new ArrayList<>();
				for (PrjFileCompltInfoDTO prjFileCompltInfoDTO : prjFileCompltInfoDTOList) {
					String cfgCd = prjFileCompltInfoDTO.getCfgCd();
					String cfgDtlCd = prjFileCompltInfoDTO.getCfgDtlCd();
					PrjPrdDtlQueryCondition dtlQC = new PrjPrdDtlQueryCondition();
					dtlQC.setPrjId(prjInsRfeRecordVO.getPrjId());
					dtlQC.setIsDel(0);
					List<PrjPrdDtlVO> prjPrdDtlVOS = prjPrdDtlService.selectList(dtlQC);
					BaseLogUtils.newLogger("资方补件资料查询项目明细结果id=" + id + ",prjPrdDtlVOS=" + JSON.toJSONString(prjPrdDtlVOS)).info();
					if (DataCheckConstant.DataCheckEnum.CUSTOMER_DATA_NATURAL.code.equals(cfgCd)) {
						getPrjFillCompltInfoList(cstFileList, prjInsRfeRecordVO.getCstId(), prjFileCompltInfoDTO, getSysUlFilesRec(prjInsRfeRecordVO.getCstId(), cfgCd, cfgDtlCd));
					} else if (DataCheckConstant.DataCheckEnum.PROJECT_DATA.code.equals(cfgCd)) {
						getPrjFillCompltInfoList(prjFileList, prjInsRfeRecordVO.getPrjId(), prjFileCompltInfoDTO, getSysUlFilesRec(prjInsRfeRecordVO.getPrjId(), cfgCd, cfgDtlCd));
					}
				}
				view.addObject("cstFileList", JSON.toJSONString(cstFileList, SerializerFeature.DisableCircularReferenceDetect));
				view.addObject("prjFileList", JSON.toJSONString(prjFileList, SerializerFeature.DisableCircularReferenceDetect));
			}
		}
		BaseLogUtils.newLogger("资方补件资料返回页面结果结果id=" + id + ",view=" + JSON.toJSONString(view)).info();
		return view;
	}

	//拼装组合数据
	private void getPrjFillCompltInfoList(List<PrjFileCompltInfoDTO> list, Long filePkId, PrjFileCompltInfoDTO prjFillCompltInfoDTO, List<SysUlFilesRecVO> sysUlFilesRecVOList) {
		BaseLogUtils.newLogger("资方补件资料拼装组合数据入参信息filePkId=" + filePkId + ",list=" + JSON.toJSONString(list) + ",prjFillCompltInfoDTO="
				+ JSON.toJSONString(prjFillCompltInfoDTO) + ",sysUlFilesRecVOList=" + JSON.toJSONString(sysUlFilesRecVOList)).info();
		if (CollectionUtils.isNotEmpty(sysUlFilesRecVOList)) {
			for (SysUlFilesRecVO sysUlFilesRecVO : sysUlFilesRecVOList) {
				PrjFileCompltInfoDTO compltInfoDTO = new PrjFileCompltInfoDTO();
				BeanUtils.copyProperties(prjFillCompltInfoDTO, compltInfoDTO);
				compltInfoDTO.setFilePkId(filePkId);
				BeanUtils.copyProperties(sysUlFilesRecVO, compltInfoDTO);
				if ("2".equals(sysUlFilesRecVO.getAudStsCd())) {
					compltInfoDTO.setAudStsCd("2");
					compltInfoDTO.setAudStsCdNm("验证未通过");
				} else if ("1".equals(sysUlFilesRecVO.getAudStsCd())) {
					compltInfoDTO.setAudStsCd("1");
					compltInfoDTO.setAudStsCdNm("已验证");
				} else {
					compltInfoDTO.setAudStsCd("0");
					compltInfoDTO.setAudStsCdNm("未验证");
				}
				list.add(compltInfoDTO);
			}
		} else {
			PrjFileCompltInfoDTO compltInfoDTO = new PrjFileCompltInfoDTO();
			BeanUtils.copyProperties(prjFillCompltInfoDTO, compltInfoDTO);
			compltInfoDTO.setFilePkId(filePkId);
			compltInfoDTO.setFileNm("");
			list.add(compltInfoDTO);
		}
		BaseLogUtils.newLogger("资方补件资料拼装组合数据结果filePkId=" + filePkId + ",list=" + JSON.toJSONString(list, SerializerFeature.DisableCircularReferenceDetect)).info();
	}

	//查询文件上传记录表数据
	private List<SysUlFilesRecVO> getSysUlFilesRec(Long pkId, String cfgCd, String cfgDtlCd) {
		SysUlFilesRecQueryCondition sysUlFilesRecQueryCondition = new SysUlFilesRecQueryCondition();
		sysUlFilesRecQueryCondition.setSysCd(PropertiesCacheUtils.getProperty(SystemConstant.FL_SERVICE_CD));
		sysUlFilesRecQueryCondition.setPkId(pkId.toString());
		sysUlFilesRecQueryCondition.setCfgCd(cfgCd);
		sysUlFilesRecQueryCondition.setCfgDtlCd(cfgDtlCd);
		sysUlFilesRecQueryCondition.setIsDel(0);
        sysUlFilesRecQueryCondition.setbId("35279a3dba524cf5a1a6c4b316046491");
        sysUlFilesRecQueryCondition.setpId("LSAENHUINSPLM");
		BaseLogUtils.newLogger("资方补件资料校验入参为sysUlFilesRecQueryCondition=" + JSON.toJSONString(sysUlFilesRecQueryCondition)).info();
		List<SysUlFilesRecVO> sysUlFilesRecVOList = sysUlFilesRecService.searchList(sysUlFilesRecQueryCondition);
		BaseLogUtils.newLogger("资方补件资料校验查询文件结果为sysUlFilesRecVOList=" + JSON.toJSONString(sysUlFilesRecVOList)).info();
		return sysUlFilesRecVOList == null ? Collections.emptyList() : sysUlFilesRecVOList;
	}

	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("institution/prjInsRfeRecord/prjInsRfeRecordList");
		BaseLogUtils.info(logger, "toListPage", "跳转到列表页面.", CurrentThreadContext.getCurrentUserName());
		String mgrPrjViewFlag = request.getParameter("mgrPrjViewFlag");//客户经理关联项目页面
		//补件状态
		List<KeyValueVO> compltStsList = this.prjInsRfeRecordService.getCompltStsList();
		//补件节点
		List<KeyValueVO> compltNodeList = this.prjInsRfeRecordService.getCompltNodeList();
		//资方付款状态
		List<KeyValueVO> payStsCdList = this.prjInsRfeRecordService.getPayStsCdList();
		//查询第三方机构
		Pager page = new Pager();
		page.setCurrentPage(1);
		page.setEveryPage(Integer.MAX_VALUE);
		FriBaseInfoQueryCondition qc = new FriBaseInfoQueryCondition();
		qc.setInsSts(FriBaseInfoConstant.FRI_BASE_INFO_INS_STS_PASS);
		qc.setInsUseCd("2");
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		page.setCondition(qc);
		Pager pager = this.friBaseInfoService.searchListPage(page);
		List<FriBaseInfoVO> list = (List<FriBaseInfoVO>) pager.getResultList();

		if("mgrPrjViewFlag".equals(mgrPrjViewFlag)){
			view.addObject("mgrPrjViewFlag",mgrPrjViewFlag);
			view.addObject("cstMgrId",request.getParameter("cstMgrId"));
		}
		view.addObject("currentUsrId", CurrentThreadContext.getCurrentUserId());//当前登录用户
		BaseLogUtils.newLogger("===当前用户组织架构===cd:{},组织架构:{}" ,JSON.toJSONString(CurrentThreadContext.getCurrentOrgCd()) , CurrentThreadContext.getCurrentOrgShtNm()).info();
		view.addObject("compltStsList",compltStsList);
		view.addObject("compltNodeList",compltNodeList);
		view.addObject("payStsCdList", payStsCdList);
		view.addObject("friBaseList", list);
		return view;
	}

	/**
	 * 到修改页面
	 */
	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("insitution/prjInsRfeRecord/modify");
		view.addObject("id", id);
		BaseLogUtils.info(logger, "toModifyPage", "跳转到修改页面.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		//获取请求参数
		Pager page = this.getRequestParameters(request);
		Pager pager = this.prjInsRfeRecordService.searchInsRfeRecordListPage(page);
		//Pager pager = this.prjInsRfeRecordService.searchListPage(page);
		List<PrjInsRfeRecordVO> list = (List<PrjInsRfeRecordVO>) pager.getResultList();
		ListPageVO<PrjInsRfeRecordVO> listPage = new ListPageVO<PrjInsRfeRecordVO>(list, pager.getTotalCount());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page.getResultList()), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	/**
	  * @Author yangzhongkun
	  * @params [request, page]
	  * @Description 获取页面请求参数
	  * @Date 2020/6/23 17:43
	  * @return cmm.mid.core.framework.page.Pager
	  **/
	private Pager getRequestParameters(HttpServletRequest request) {
		Pager page = new Pager();
		String currentPage = request.getParameter("page");//当前页数
		String pageSize = request.getParameter("pagesize");//条目数
		String lsCntNo = request.getParameter("lsCntNo");//合同号
		String cstNm = request.getParameter("cstNm");//客户姓名
		String actPayTmBg = request.getParameter("actPayTmBg");//资方放款时间开始
		String actPayTmEd = request.getParameter("actPayTmEd");//资方放款时间结束
		String compltStsCd = request.getParameter("compltStsCd");//补件状态
		String insCode = request.getParameter("insCode");//机构code
		String compltNodeCd = request.getParameter("compltNodeCd");//补件节点
		String payStsCd = request.getParameter("payStsCd");//资方放款状态


		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		PrjInsRfeRecordQC qc = new PrjInsRfeRecordQC();

		if (StringUtils.isNotEmpty(lsCntNo)) {
			qc.setLsCntNo(lsCntNo);
		}

		if(StringUtils.isNotEmpty(cstNm)){
			qc.setCstNm(cstNm);
		}

		if(StringUtils.isNotEmpty(actPayTmBg)){
			qc.setActPayTmBg(DateUtils.formatStringToDate(actPayTmBg,DateUtils.YYYY_MM_DD));
		}

		if(StringUtils.isNotEmpty(actPayTmEd)){
			qc.setActPayTmEd(DateUtils.formatStringToDate(actPayTmEd,DateUtils.YYYY_MM_DD));
		}

		if(StringUtils.isNotEmpty(compltStsCd)){
			qc.setCompltStsCd(compltStsCd);
		}

		if(StringUtils.isNotEmpty(insCode)){
			qc.setInsCode(insCode);
		}

		if(StringUtils.isNotEmpty(compltNodeCd)){
			qc.setCompltNodeCd(compltNodeCd);
		}

		if(StringUtils.isNotEmpty(payStsCd)){
			qc.setPayStsCd(payStsCd);
		}
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		qc.setUsrId(CurrentThreadContext.getCurrentUserId());
		page.setCondition(qc);
		return page;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeById.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		try {
			this.prjInsRfeRecordService.removeById(Long.valueOf(id));
			BaseLogUtils.info(logger, "removeById", "删除数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "removeById", "删除数据失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "removeById", "删除数据失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			PrjInsRfeRecordVO vo = this.prjInsRfeRecordService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String name = request.getParameter("name");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		PrjInsRfeRecordVO entity = null;
		try {
			entity = new PrjInsRfeRecordVO();
			//TODO ADD PARAM
			Long id = this.prjInsRfeRecordService.add(entity);
			result.setData(id);
			BaseLogUtils.info(logger, "add", "新增数据.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		String name = request.getParameter("name");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		PrjInsRfeRecordVO entity = null;
		try {
			entity = new PrjInsRfeRecordVO();
			entity.setId(Long.valueOf(id));
			//entity.setName(name);
			//TODO ADD PARAM
			boolean success = this.prjInsRfeRecordService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 获取租赁物信息
	 */
	@RequestMapping(value = "/selectPrjPrdDtlList.do", method = {RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	public Object selectPrjPrdDtlList(HttpServletRequest request, HttpServletResponse response) {
		String prjId = request.getParameter("prjId");//项目ID
		String dataId = request.getParameter("dataId");//资方补件记录id(对应流程中dataId)
		if(StringUtils.isEmpty(prjId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "项目ID不能为空.");
		}
		if(StringUtils.isEmpty(dataId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "资方补件记录id不能为空.");
		}
		List<PrjPrdDtlVO> prjPrdDtlVOList = new ArrayList<>();
		PrjPrdDtlQueryCondition qc = new PrjPrdDtlQueryCondition();
		qc.setPrjId(Long.valueOf(prjId));
		qc.setIsDel(0);
		BaseLogUtils.newLogger("查询租赁物信息数据入参qc:" + JSON.toJSONString(qc)).info();
		List<PrjPrdDtlVO> prjPrdDtlList = prjPrdDtlService.selectList(qc);
		BaseLogUtils.newLogger("查询租赁物信息数据返回结果prjPrdDtlList:" + JSON.toJSONString(prjPrdDtlList)).info();
		if(CollectionUtils.isNotEmpty(prjPrdDtlList)){
			PrjInsRfeRecordQC prjInsRfeRecordQC = new PrjInsRfeRecordQC();
			prjInsRfeRecordQC.setIsDel(0);
			prjInsRfeRecordQC.setId(Long.parseLong(dataId));
			List<PrjInsRfeRecordVO> prjInsRfeRecordVOS = prjInsRfeRecordService.queryAll(prjInsRfeRecordQC);
			BaseLogUtils.newLogger("获取资方租赁物补件资料校验查询结果prjId=" + prjId + ",dataId=" + dataId + ",prjInsRfeRecordVOS=" + JSON.toJSONString(prjInsRfeRecordVOS)).info();
			if (CollectionUtils.isNotEmpty(prjInsRfeRecordVOS) && prjInsRfeRecordVOS.get(0) != null) {
				PrjInsRfeRecordVO prjInsRfeRecordVO = prjInsRfeRecordVOS.get(0);
				List list = JSON.parseObject(prjInsRfeRecordVO.getRefDataCode(), List.class);
				BaseLogUtils.newLogger("资方租赁物补件资料转换结果prjId=" + prjId + ",list=" + JSON.toJSONString(list)).info();
				List<PrjFileCompltInfoDTO> prjFileCompltInfoDTOList = new ArrayList<>();
				for (Object o : list) {
					prjFileCompltInfoDTOList.add(JSON.parseObject(JSON.toJSONString(o), PrjFileCompltInfoDTO.class));
				}
				if (CollectionUtils.isNotEmpty(prjFileCompltInfoDTOList)) {
					for (PrjPrdDtlVO prdDtlVO : prjPrdDtlList){
						boolean flag = false;
						for (PrjFileCompltInfoDTO prjFileCompltInfoDTO : prjFileCompltInfoDTOList) {
							String cfgCd = prjFileCompltInfoDTO.getCfgCd();
							if (DataCheckConstant.DataCheckEnum.PROJECT_PRODUCT_DATA.code.equals(cfgCd)) {
								//有我司支付表号的，仅展我司支付表号的资料；无我司支付表号的，展示我司所有支付表号的资料
								if (StringUtils.isNotEmpty(prjFileCompltInfoDTO.getWsPaySchNo())){
									if (prdDtlVO.getPaySchNo().equals(prjFileCompltInfoDTO.getWsPaySchNo())){
										flag = true;
									}
								}else {
									flag = true;
								}
							}
						}
						if (flag){
							prjPrdDtlVOList.add(prdDtlVO);
						}
					}
				}
			}
			BaseLogUtils.newLogger("租赁物信息最终返回接果prjPrdDtlVOList:" + JSON.toJSONString(prjPrdDtlVOList)).info();
		}
		ListPageVO<PrjPrdDtlVO> listPage = new ListPageVO<PrjPrdDtlVO>(prjPrdDtlVOList, prjPrdDtlVOList.size());
		return listPage;
	}

	/**
	 * 到租赁物资料页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toPrjPrdDtlFileInfoList.do", method = {RequestMethod.GET, RequestMethod.POST})
	public ModelAndView toPrjPrdDtlFileInfoList(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("/institution/prjInsRfeRecord/prjPrdDtlFileInfoList");
		String prjPrdDtlId = request.getParameter("prjPrdDtlId");//项目产品明细ID
		String detailFlag = request.getParameter("detailFlag");//如果为true 则跳转到修改页面
		String fileNode = request.getParameter("fileNode");//补件节点 1上传或2验证
		String prjId = request.getParameter("prjId");//项目ID
		String paySchId = request.getParameter("paySchId");//支付表ID
		String paySchNo = request.getParameter("paySchNo");//支付表号
		String dataId = request.getParameter("dataId");//资方补件记录id(对应流程中dataId)

		view.addObject("fileNode", fileNode);//补件节点 1上传或2验证
		view.addObject("detailFlag", detailFlag);//如果为true 则跳转到修改页面
		view.addObject("prjPrdDtlId", prjPrdDtlId);
		view.addObject("prjId", prjId);
		view.addObject("paySchId", paySchId);
		view.addObject("paySchNo", paySchNo);
		PrjInsRfeRecordQC prjInsRfeRecordQC = new PrjInsRfeRecordQC();
		prjInsRfeRecordQC.setIsDel(0);
		prjInsRfeRecordQC.setId(Long.parseLong(dataId));
		List<PrjInsRfeRecordVO> prjInsRfeRecordVOS = prjInsRfeRecordService.queryAll(prjInsRfeRecordQC);
		BaseLogUtils.newLogger("资方租赁物补件资料校验查询结果prjId=" + prjId + ",dataId=" + dataId + ",prjInsRfeRecordVOS=" + JSON.toJSONString(prjInsRfeRecordVOS)).info();
		if (CollectionUtils.isNotEmpty(prjInsRfeRecordVOS) && prjInsRfeRecordVOS.get(0) != null) {
			PrjInsRfeRecordVO prjInsRfeRecordVO = prjInsRfeRecordVOS.get(0);
			view.addObject("prjInsRfeRecordVO", prjInsRfeRecordVO);
			List list = JSON.parseObject(prjInsRfeRecordVO.getRefDataCode(), List.class);
			BaseLogUtils.newLogger("资方租赁物补件资料转换结果prjId=" + prjId + ",list=" + JSON.toJSONString(list)).info();
			List<PrjFileCompltInfoDTO> prjFileCompltInfoDTOList = new ArrayList<>();
			for (Object o : list) {
				prjFileCompltInfoDTOList.add(JSON.parseObject(JSON.toJSONString(o), PrjFileCompltInfoDTO.class));
			}
			BaseLogUtils.newLogger("资方租赁物补件资料转换实体对象结果prjId=" + prjId + ",prjFileCompltInfoDTOList=" + JSON.toJSONString(prjFileCompltInfoDTOList)).info();
			for (PrjFileCompltInfoDTO prjFileCompltInfoDTO : prjFileCompltInfoDTOList) {
				prjFileCompltInfoDTO.setFileName(prjFileCompltInfoDTO.getFileNm());
			}
			BaseLogUtils.newLogger("资方租赁物补件资料重命名文件名称结果prjId=" + prjId + ",prjFileCompltInfoDTOList=" + JSON.toJSONString(prjFileCompltInfoDTOList)).info();
			if (CollectionUtils.isNotEmpty(prjFileCompltInfoDTOList)) {
				//客户资料(自然人和法人)、项目资料、租赁物资料、发票资料、保单资料
				List<PrjFileCompltInfoDTO> prjPrdFileList = new ArrayList<>();
				for (PrjFileCompltInfoDTO prjFileCompltInfoDTO : prjFileCompltInfoDTOList) {
					String cfgCd = prjFileCompltInfoDTO.getCfgCd();
					String cfgDtlCd = prjFileCompltInfoDTO.getCfgDtlCd();
					if (DataCheckConstant.DataCheckEnum.PROJECT_PRODUCT_DATA.code.equals(cfgCd)) {
						if (StringUtils.isNotEmpty(prjFileCompltInfoDTO.getWsPaySchNo())){
							if (paySchNo.equals(prjFileCompltInfoDTO.getWsPaySchNo())){
								getPrjFillCompltInfoList(prjPrdFileList, Long.valueOf(prjPrdDtlId), prjFileCompltInfoDTO, getSysUlFilesRec(Long.valueOf(prjPrdDtlId), cfgCd, cfgDtlCd));
							}
						}else {
							getPrjFillCompltInfoList(prjPrdFileList, Long.valueOf(prjPrdDtlId), prjFileCompltInfoDTO, getSysUlFilesRec(Long.valueOf(prjPrdDtlId), cfgCd, cfgDtlCd));
						}
						BaseLogUtils.newLogger("资方租赁物补件资料租赁物资料prjId=" + prjId + ",prjPrdFileList=" + JSON.toJSONString(prjPrdFileList)).info();
					}
				}
				view.addObject("prjPrdFileList", JSON.toJSONString(prjPrdFileList));
			}
		}
		return view;
	}

	/**
	 * 获取发票信息
	 */
	@RequestMapping(value = "/selectPrjPrdInvoiceList.do", method = {RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	public Object selectPrjPrdInvoiceList(HttpServletRequest request, HttpServletResponse response) {
		String prjId = request.getParameter("prjId");//项目ID
		String dataId = request.getParameter("dataId");//资方补件记录id(对应流程中dataId)
		if(StringUtils.isEmpty(prjId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "项目ID不能为空.");
		}
		if(StringUtils.isEmpty(dataId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "资方补件记录id不能为空.");
		}
		List<PrjPrdInvoiceVO> prjPrdInvoiceVOList = new ArrayList<>();
		PrjPrdInvoiceQueryCondition qc = new PrjPrdInvoiceQueryCondition();
		qc.setPrjId(prjId);
		qc.setFlag(PrjPrdBscInfoConstant.PRJ_PRD_FILE_INVOICE_CODE_10);
		BaseLogUtils.newLogger("查询发票信息数据入参qc:" + JSON.toJSONString(qc)).info();
		List<PrjPrdInvoiceVO> prjPrdInvoiceList = prjPrdInvoiceService.searchPrjPrdInvoiceList(qc);
		BaseLogUtils.newLogger("查询发票信息数据返回结果prjPrdInvoiceList:" + JSON.toJSONString(prjPrdInvoiceList)).info();
		if(CollectionUtils.isNotEmpty(prjPrdInvoiceList)){
			PrjInsRfeRecordQC prjInsRfeRecordQC = new PrjInsRfeRecordQC();
			prjInsRfeRecordQC.setIsDel(0);
			prjInsRfeRecordQC.setId(Long.parseLong(dataId));
			List<PrjInsRfeRecordVO> prjInsRfeRecordVOS = prjInsRfeRecordService.queryAll(prjInsRfeRecordQC);
			BaseLogUtils.newLogger("获取资方租赁物补件资料校验查询结果prjId=" + prjId + ",dataId=" + dataId + ",prjInsRfeRecordVOS=" + JSON.toJSONString(prjInsRfeRecordVOS)).info();
			if (CollectionUtils.isNotEmpty(prjInsRfeRecordVOS) && prjInsRfeRecordVOS.get(0) != null) {
				PrjInsRfeRecordVO prjInsRfeRecordVO = prjInsRfeRecordVOS.get(0);
				List list = JSON.parseObject(prjInsRfeRecordVO.getRefDataCode(), List.class);
				BaseLogUtils.newLogger("资方租赁物补件资料转换结果prjId=" + prjId + ",list=" + JSON.toJSONString(list)).info();
				List<PrjFileCompltInfoDTO> prjFileCompltInfoDTOList = new ArrayList<>();
				for (Object o : list) {
					prjFileCompltInfoDTOList.add(JSON.parseObject(JSON.toJSONString(o), PrjFileCompltInfoDTO.class));
				}
				if (CollectionUtils.isNotEmpty(prjFileCompltInfoDTOList)) {
					for (PrjPrdInvoiceVO prjPrdInvoiceVO : prjPrdInvoiceList){
						boolean flag = false;
						for (PrjFileCompltInfoDTO prjFileCompltInfoDTO : prjFileCompltInfoDTOList) {
							String cfgCd = prjFileCompltInfoDTO.getCfgCd();
							if (DataCheckConstant.DataCheckEnum.INVOICE_DATA.code.equals(cfgCd)) {
								//有我司支付表号的，仅展我司支付表号的资料；无我司支付表号的，展示我司所有支付表号的资料
								if (StringUtils.isNotEmpty(prjFileCompltInfoDTO.getWsPaySchNo())){
									if (prjPrdInvoiceVO.getPaySchNo().equals(prjFileCompltInfoDTO.getWsPaySchNo())){
										flag = true;
									}
								}else {
									flag = true;
								}
							}
						}
						if (flag){
							prjPrdInvoiceVOList.add(prjPrdInvoiceVO);
						}
					}
				}
			}
			BaseLogUtils.newLogger("发票信息最终返回接果prjPrdInvoiceVOList:" + JSON.toJSONString(prjPrdInvoiceVOList)).info();
		}
		ListPageVO<PrjPrdInvoiceVO> listPage = new ListPageVO<PrjPrdInvoiceVO>(prjPrdInvoiceVOList, prjPrdInvoiceVOList.size());
		return listPage;
	}

	/**
	 * 到发票资料页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toPrjPrdInvoiceFileInfoList.do", method = {RequestMethod.GET, RequestMethod.POST})
	public ModelAndView toPrjPrdInvoiceFileInfoList(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("/institution/prjInsRfeRecord/prjPrdInvoiceFileInfoList");
		String prjPrdInvoiceId = request.getParameter("prjPrdInvoiceId");//发票ID
		String detailFlag = request.getParameter("detailFlag");//如果为true 则跳转到修改页面
		String fileNode = request.getParameter("fileNode");//补件节点 1上传或2验证
		String prjId = request.getParameter("prjId");//项目ID
		String paySchId = request.getParameter("paySchId");//支付表ID
		String paySchNo = request.getParameter("paySchNo");//支付表号
		String dataId = request.getParameter("dataId");//资方补件记录id(对应流程中dataId)

		view.addObject("fileNode", fileNode);//补件节点 1上传或2验证
		view.addObject("detailFlag", detailFlag);//如果为true 则跳转到修改页面
		view.addObject("prjPrdInvoiceId", prjPrdInvoiceId);
		view.addObject("prjId", prjId);
		view.addObject("paySchId", paySchId);
		view.addObject("paySchNo", paySchNo);
		PrjInsRfeRecordQC prjInsRfeRecordQC = new PrjInsRfeRecordQC();
		prjInsRfeRecordQC.setIsDel(0);
		prjInsRfeRecordQC.setId(Long.parseLong(dataId));
		List<PrjInsRfeRecordVO> prjInsRfeRecordVOS = prjInsRfeRecordService.queryAll(prjInsRfeRecordQC);
		BaseLogUtils.newLogger("资方发票补件资料校验查询结果prjId=" + prjId + ",dataId=" + dataId + ",prjInsRfeRecordVOS=" + JSON.toJSONString(prjInsRfeRecordVOS)).info();
		if (CollectionUtils.isNotEmpty(prjInsRfeRecordVOS) && prjInsRfeRecordVOS.get(0) != null) {
			PrjInsRfeRecordVO prjInsRfeRecordVO = prjInsRfeRecordVOS.get(0);
			view.addObject("prjInsRfeRecordVO", prjInsRfeRecordVO);
			List list = JSON.parseObject(prjInsRfeRecordVO.getRefDataCode(), List.class);
			BaseLogUtils.newLogger("资方发票补件资料转换结果prjId=" + prjId + ",list=" + JSON.toJSONString(list)).info();
			List<PrjFileCompltInfoDTO> prjFileCompltInfoDTOList = new ArrayList<>();
			for (Object o : list) {
				prjFileCompltInfoDTOList.add(JSON.parseObject(JSON.toJSONString(o), PrjFileCompltInfoDTO.class));
			}
			BaseLogUtils.newLogger("资方发票补件资料转换实体对象结果prjId=" + prjId + ",prjFileCompltInfoDTOList=" + JSON.toJSONString(prjFileCompltInfoDTOList)).info();
			for (PrjFileCompltInfoDTO prjFileCompltInfoDTO : prjFileCompltInfoDTOList) {
				prjFileCompltInfoDTO.setFileName(prjFileCompltInfoDTO.getFileNm());
			}
			BaseLogUtils.newLogger("资方发票补件资料重命名文件名称结果prjId=" + prjId + ",prjFileCompltInfoDTOList=" + JSON.toJSONString(prjFileCompltInfoDTOList)).info();
			if (CollectionUtils.isNotEmpty(prjFileCompltInfoDTOList)) {
				//客户资料(自然人和法人)、项目资料、租赁物资料、发票资料、保单资料
				List<PrjFileCompltInfoDTO> invoiceFileList = new ArrayList<>();
				for (PrjFileCompltInfoDTO prjFileCompltInfoDTO : prjFileCompltInfoDTOList) {
					String cfgCd = prjFileCompltInfoDTO.getCfgCd();
					String cfgDtlCd = prjFileCompltInfoDTO.getCfgDtlCd();
					if (DataCheckConstant.DataCheckEnum.INVOICE_DATA.code.equals(cfgCd)) {
						if (StringUtils.isNotEmpty(prjFileCompltInfoDTO.getWsPaySchNo())){
							if (paySchNo.equals(prjFileCompltInfoDTO.getWsPaySchNo())){
								getPrjFillCompltInfoList(invoiceFileList, Long.valueOf(prjPrdInvoiceId), prjFileCompltInfoDTO, getSysUlFilesRec(Long.valueOf(prjPrdInvoiceId), cfgCd, cfgDtlCd));
							}
						}else {
							getPrjFillCompltInfoList(invoiceFileList, Long.valueOf(prjPrdInvoiceId), prjFileCompltInfoDTO, getSysUlFilesRec(Long.valueOf(prjPrdInvoiceId), cfgCd, cfgDtlCd));
						}
						BaseLogUtils.newLogger("资方发票补件资料租赁物资料prjId=" + prjId + ",invoiceFileList=" + JSON.toJSONString(invoiceFileList)).info();
					}
				}
				view.addObject("invoiceFileList", JSON.toJSONString(invoiceFileList));
			}
		}
		return view;
	}

	/**
	 * 获取保单信息
	 */
	@RequestMapping(value = "/selectInsPlcBscInfoList.do", method = {RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	public Object selectInsPlcBscInfoList(HttpServletRequest request, HttpServletResponse response) {
		String prjId = request.getParameter("prjId");//项目ID
		String dataId = request.getParameter("dataId");//资方补件记录id(对应流程中dataId)
		if(StringUtils.isEmpty(prjId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "项目ID不能为空.");
		}
		if(StringUtils.isEmpty(dataId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "资方补件记录id不能为空.");
		}
		List<InsPlcBscInfoVO> insPlcBscInfoVOList = new ArrayList<>();
		InsPlcBscInfoQueryCondition qc = new InsPlcBscInfoQueryCondition();
		qc.setPrjId(Long.valueOf(prjId));
		qc.setSysCd("11000");
		GetInsPlcBscInfoListRequest getListRequest = new GetInsPlcBscInfoListRequest(qc);
		getListRequest.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		getListRequest.setSysCd(CurrentThreadContext.getCurrentSysCd());
		BaseLogUtils.newLogger("查询保单信息数据入参getListRequest:" + JSON.toJSONString(getListRequest)).info();
		ResponseData<List<InsPlcBscInfoDTO>> infoResponse = insPlcBscInfoService.searchList(getListRequest);
		BaseLogUtils.newLogger("查询保单信息数据返回结果infoResponse:" + JSON.toJSONString(infoResponse)).info();
		if (null != infoResponse && ResponseData.SUCCESS_CODE.equals(infoResponse.getCode()) && CollectionUtils.isNotEmpty(infoResponse.getData())){
			PrjInsRfeRecordQC prjInsRfeRecordQC = new PrjInsRfeRecordQC();
			prjInsRfeRecordQC.setIsDel(0);
			prjInsRfeRecordQC.setId(Long.parseLong(dataId));
			List<PrjInsRfeRecordVO> prjInsRfeRecordVOS = prjInsRfeRecordService.queryAll(prjInsRfeRecordQC);
			BaseLogUtils.newLogger("获取资方租赁物补件资料校验查询结果prjId=" + prjId + ",dataId=" + dataId + ",prjInsRfeRecordVOS=" + JSON.toJSONString(prjInsRfeRecordVOS)).info();
			if (CollectionUtils.isNotEmpty(prjInsRfeRecordVOS) && prjInsRfeRecordVOS.get(0) != null) {
				PrjInsRfeRecordVO prjInsRfeRecordVO = prjInsRfeRecordVOS.get(0);
				List list = JSON.parseObject(prjInsRfeRecordVO.getRefDataCode(), List.class);
				BaseLogUtils.newLogger("资方租赁物补件资料转换结果prjId=" + prjId + ",list=" + JSON.toJSONString(list)).info();
				List<PrjFileCompltInfoDTO> prjFileCompltInfoDTOList = new ArrayList<>();
				for (Object o : list) {
					prjFileCompltInfoDTOList.add(JSON.parseObject(JSON.toJSONString(o), PrjFileCompltInfoDTO.class));
				}
				if (CollectionUtils.isNotEmpty(prjFileCompltInfoDTOList)) {
					for (InsPlcBscInfoDTO insPlcBscInfoDTO : infoResponse.getData()) {
						boolean flag = false;
						InsPlcBscInfoVO insPlcBscInfoVO = new InsPlcBscInfoVO();
						BeanUtils.copyProperties(insPlcBscInfoDTO,insPlcBscInfoVO);
						for (PrjFileCompltInfoDTO prjFileCompltInfoDTO : prjFileCompltInfoDTOList) {
							String cfgCd = prjFileCompltInfoDTO.getCfgCd();
							if (DataCheckConstant.DataCheckEnum.INSURANCE_DATA.code.equals(cfgCd)) {
								//有我司支付表号的，仅展我司支付表号的资料；无我司支付表号的，展示我司所有支付表号的资料
								if (StringUtils.isNotEmpty(prjFileCompltInfoDTO.getWsPaySchNo())){
									if (insPlcBscInfoDTO.getPaySchNo().equals(prjFileCompltInfoDTO.getWsPaySchNo())){
										flag = true;
									}
								}else {
									flag = true;
								}
							}
						}
						if (flag){
							insPlcBscInfoVOList.add(insPlcBscInfoVO);
						}
					}
				}
			}
			BaseLogUtils.newLogger("保单信息最终返回接果insPlcBscInfoVOList:" + JSON.toJSONString(insPlcBscInfoVOList)).info();
		}
		ListPageVO<InsPlcBscInfoVO> listPage = new ListPageVO<InsPlcBscInfoVO>(insPlcBscInfoVOList, insPlcBscInfoVOList.size());
		return listPage;
	}

	/**
	 * 到保单资料页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toInsPlcBscInfoFileInfoList.do", method = {RequestMethod.GET, RequestMethod.POST})
	public ModelAndView toInsPlcBscInfoFileInfoList(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("/institution/prjInsRfeRecord/insPlcBscInfoFileInfoList");
		String plcId = request.getParameter("plcId");//保单ID
		String detailFlag = request.getParameter("detailFlag");//如果为true 则跳转到修改页面
		String fileNode = request.getParameter("fileNode");//补件节点 1上传或2验证
		String prjId = request.getParameter("prjId");//项目ID
		String paySchId = request.getParameter("paySchId");//支付表ID
		String paySchNo = request.getParameter("paySchNo");//支付表号
		String dataId = request.getParameter("dataId");//资方补件记录id(对应流程中dataId)

		view.addObject("fileNode", fileNode);//补件节点 1上传或2验证
		view.addObject("detailFlag", detailFlag);//如果为true 则跳转到修改页面
		view.addObject("plcId", plcId);
		view.addObject("prjId", prjId);
		view.addObject("paySchId", paySchId);
		view.addObject("paySchNo", paySchNo);
		PrjInsRfeRecordQC prjInsRfeRecordQC = new PrjInsRfeRecordQC();
		prjInsRfeRecordQC.setIsDel(0);
		prjInsRfeRecordQC.setId(Long.parseLong(dataId));
		List<PrjInsRfeRecordVO> prjInsRfeRecordVOS = prjInsRfeRecordService.queryAll(prjInsRfeRecordQC);
		BaseLogUtils.newLogger("资方保单补件资料校验查询结果prjId=" + prjId + ",dataId=" + dataId + ",prjInsRfeRecordVOS=" + JSON.toJSONString(prjInsRfeRecordVOS)).info();
		if (CollectionUtils.isNotEmpty(prjInsRfeRecordVOS) && prjInsRfeRecordVOS.get(0) != null) {
			PrjInsRfeRecordVO prjInsRfeRecordVO = prjInsRfeRecordVOS.get(0);
			view.addObject("prjInsRfeRecordVO", prjInsRfeRecordVO);
			List list = JSON.parseObject(prjInsRfeRecordVO.getRefDataCode(), List.class);
			BaseLogUtils.newLogger("资方保单补件资料转换结果prjId=" + prjId + ",list=" + JSON.toJSONString(list)).info();
			List<PrjFileCompltInfoDTO> prjFileCompltInfoDTOList = new ArrayList<>();
			for (Object o : list) {
				prjFileCompltInfoDTOList.add(JSON.parseObject(JSON.toJSONString(o), PrjFileCompltInfoDTO.class));
			}
			BaseLogUtils.newLogger("资方保单补件资料转换实体对象结果prjId=" + prjId + ",prjFileCompltInfoDTOList=" + JSON.toJSONString(prjFileCompltInfoDTOList)).info();
			for (PrjFileCompltInfoDTO prjFileCompltInfoDTO : prjFileCompltInfoDTOList) {
				prjFileCompltInfoDTO.setFileName(prjFileCompltInfoDTO.getFileNm());
			}
			BaseLogUtils.newLogger("资方保单补件资料重命名文件名称结果prjId=" + prjId + ",prjFileCompltInfoDTOList=" + JSON.toJSONString(prjFileCompltInfoDTOList)).info();
			if (CollectionUtils.isNotEmpty(prjFileCompltInfoDTOList)) {
				//客户资料(自然人和法人)、项目资料、租赁物资料、发票资料、保单资料
				List<PrjFileCompltInfoDTO> insPlcFileList = new ArrayList<>();
				for (PrjFileCompltInfoDTO prjFileCompltInfoDTO : prjFileCompltInfoDTOList) {
					String cfgCd = prjFileCompltInfoDTO.getCfgCd();
					String cfgDtlCd = prjFileCompltInfoDTO.getCfgDtlCd();
					if (DataCheckConstant.DataCheckEnum.INSURANCE_DATA.code.equals(cfgCd)) {
						if (StringUtils.isNotEmpty(prjFileCompltInfoDTO.getWsPaySchNo())){
							if (paySchNo.equals(prjFileCompltInfoDTO.getWsPaySchNo())){
								getPrjFillCompltInfoList(insPlcFileList, Long.valueOf(plcId), prjFileCompltInfoDTO, getSysUlFilesRec(Long.valueOf(plcId), cfgCd, cfgDtlCd));
							}
						}else {
							getPrjFillCompltInfoList(insPlcFileList, Long.valueOf(plcId), prjFileCompltInfoDTO, getSysUlFilesRec(Long.valueOf(plcId), cfgCd, cfgDtlCd));
						}
						BaseLogUtils.newLogger("资方保单补件资料租赁物资料prjId=" + prjId + ",insPlcFileList=" + JSON.toJSONString(insPlcFileList)).info();
					}
				}
				view.addObject("insPlcFileList", JSON.toJSONString(insPlcFileList));
			}
		}
		return view;
	}
}

